#ifdef GL_FRAGMENT_PRECISION_HIGH
	precision highp float;
	precision highp int;
#else
	precision mediump float;
	precision mediump int;
#endif

#include "Lighting.glsl";
#include "GlobalIllumination.glsl";//"GlobalIllumination.glsl use uniform should at front of this

uniform sampler2D u_DiffuseTexture;
uniform sampler2D u_NoiseTex;

varying vec3 v_Normal;

// #if defined(DIRECTIONLIGHT)
varying vec3 v_ViewDir; 
uniform vec3 u_MaterialSpecular;
uniform float u_Shininess;

uniform mat4 u_View;
uniform vec4 u_ProjectionParams;
uniform vec4 u_Viewport;
uniform int u_DirationLightCount;
uniform sampler2D u_LightBuffer;
uniform sampler2D u_LightClusterBuffer;
uniform float u_Time;
uniform float u_WaterScale;

varying vec2 v_Texcoord0;

void main()
{
	vec3 normal = normalize(v_Normal);
	vec3 viewDir= normalize(v_ViewDir);
	LayaGIInput giInput;
	vec3 globalDiffuse=layaGIBase(giInput,1.0,normal);

	vec4 difTexColor=vec4(texture2D(u_DiffuseTexture, v_Texcoord0).rgb,0.6);
	vec4 mainColor=difTexColor;
	vec3 diffuse = vec3(0.0);
	vec3 specular= vec3(0.0);
	vec3 dif,spe;
	vec3 gloss=vec3(difTexColor.a);

	for (int i = 0; i < MAX_LIGHT_COUNT; i++) 
	{
		if(i >= u_DirationLightCount)
			break;
		DirectionLight directionLight = getDirectionLight(u_LightBuffer,i);
		LayaAirBlinnPhongDiectionLight(u_MaterialSpecular,u_Shininess,normal,gloss,viewDir,directionLight,dif,spe);
		diffuse+=dif;
		specular+=spe;
	}
	
	// 水波相关代码 begin
	float _NoiseSpeedX = 0.02;
	float _NoiseSpeedY = 0.02;
	float _NoiseScaleX = u_WaterScale;
	float _NoiseScaleY = u_WaterScale;
	float _NoiseBrightOffset = 0.0;

	vec2 tuv1 = v_Texcoord0 + vec2(u_Time * _NoiseSpeedX,0);
	vec2 tuv2 = v_Texcoord0 + vec2(0,u_Time * _NoiseSpeedY);
	vec2 ouvxy = vec2(texture2D(u_NoiseTex,tuv1).r,texture2D(u_NoiseTex,tuv2).r);
	ouvxy -= _NoiseBrightOffset;
	ouvxy *= vec2(_NoiseScaleX, _NoiseScaleY);
	vec4 col = texture2D(u_DiffuseTexture,v_Texcoord0 + ouvxy);
	// 水波相关代码 end

	// 水波其他的都是光照的计算
	gl_FragColor =vec4(col.rgb*(globalDiffuse + diffuse),mainColor.a);
	gl_FragColor.rgb+=specular;
}